home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / serial_lib / error_dlog.c next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  1.9 KB  |  90 lines  |  [TEXT/KAHL]

  1. /* error_dlog.c 
  2.  * 
  3.  * 5/4/94 by Darrell Anderson
  4.  * brings up a window with a string and a number (OSErr, typically).
  5.  */
  6.  
  7.  #include <Packages.h>
  8.  #include <string.h>
  9.  #include "error_dlog.h"
  10.  
  11.  #define k_dlogH 100
  12.  #define k_dlogV 100
  13.  #define k_dlogWidth 450
  14.  #define k_dlogHeight 72
  15.  
  16.  void ReportError( char *errMsg, short errNum )
  17.  //
  18.  // bring up a window to display an error message in.  wait for a mouseclick, then
  19.  // exitToShell();
  20.  //
  21.  // an option to continue would be nice..
  22.  //
  23.  {
  24.      WindowPtr        errWinPtr;
  25.      Rect            winRect;
  26.      GrafPtr            oldPort;
  27.      Str255            errNumStr;
  28.      Str255             errTextStr;
  29.      short            strlength;
  30.      short             fontNum;
  31.      
  32.      // convert the c-string to a pascal string:
  33.      
  34.      // get the length of the string in characters
  35.      strlength = strlen( errMsg );
  36.      
  37.      // truncate anything over 255 characters
  38.      if( strlength > 255 )
  39.          strlength = 255;
  40.      
  41.      // set the length byte    
  42.      *((char *)errTextStr) = (unsigned char) strlength;
  43.      
  44.      // copy the string over
  45.      strncpy( (char *)(errTextStr+1), errMsg, strlength );
  46.      
  47.      GetPort( &oldPort );
  48.      
  49.      // what rect should the window occupy? (in global coords)
  50.      SetRect( &winRect, k_dlogH, k_dlogV, k_dlogH + k_dlogWidth, k_dlogV + k_dlogHeight );
  51.      
  52.      errWinPtr = NewWindow( nil, &winRect, "\pErrorWindow", false, dBoxProc, 
  53.                              (WindowPtr)-1L, false, 0L );
  54.      
  55.      ShowWindow( errWinPtr );
  56.      SetPort( errWinPtr );
  57.  
  58.     MoveTo( 13,23 );
  59.     
  60.     TextFace( bold );
  61.     DrawString( "\pError: " );
  62.     TextFace( normal );
  63.     
  64.     // write the error message
  65.     DrawString( errTextStr );
  66.     
  67.     // write the associated OSErr number (or whatever was passed..)
  68.     MoveTo( 13,40 );
  69.     NumToString( errNum, &errNumStr );
  70.     TextFace( bold );
  71.     DrawString( "\pErrNum: " );
  72.     TextFace( normal );
  73.     
  74.     // write the actual number
  75.     DrawString( errNumStr );
  76.     
  77.     MoveTo( 13, 57 );
  78.     DrawString( "\pPress the mouse button to exit." );
  79.     
  80.     while( !Button() )
  81.         ;
  82.     
  83.     SetPort( oldPort );
  84.     
  85.     HideWindow( errWinPtr );
  86.     DisposeWindow( errWinPtr );
  87.     
  88.     ExitToShell();
  89. }
  90.